package igame.poker.serverside.core;

import igame.poker.serverside.event.*;

import java.util.*;

/**
 * 应用程序信息
 * 
 * @author AfritXia
 *
 */
public class ApplicationInfo implements IDataEventListener {
	/**
	 * 客户端列表
	 * 
	 */
	private ArrayList<ClientProxy> _clientArray = null;

	/**
	 * 添加客户端
	 * 
	 * @param cl 
	 * 
	 */
	public void addClient(ClientProxy cl) {
		if (cl == null) {
			return;
		}

		if (this._clientArray == null) {
			this._clientArray = new ArrayList<ClientProxy>();
		}

		this._clientArray.add(cl);

		// 添加数据事件监听器
		cl.addDataEventListener(this);

		for (ClientProxy t : this._clientArray) {
			// 令客户端接收字符串
			t.receiveString("hello!!");
		}
	}

	@Override
	public void handle(DataEvent event) {
		if (event == null) {
			return;
		}

		if (this._clientArray == null) {
			return;
		}

		for (ClientProxy cl : this._clientArray) {
			// 打印调试信息
			System.out.println(String.format("DEBUG: client.receiveString( %s )", (String)event.getData()));

			// 令客户端接收字符串
			cl.receiveString((String)event.getData());
		}
	}
}
